<?php
use yii\widgets\LinkPager;
?>
<style type="text/css">
.myApproval .myApproval-table tbody tr td:nth-child(4) {
    width: 10%;
    text-align: center;
}

.myApproval-table tr td:nth-child(8) span,
.myApproval-table tr td,
.myApproval-table tr th {
	text-align: left!important;
}

.myApproval-table tr td:first-child,
.myApproval-table tr td:nth-child(7) span,
.myApproval-table tr th:nth-child(7),
.myApproval-table tr td:nth-child(6) span,
.myApproval-table tr th:nth-child(6),
.myApproval-table tr th:first-child {
	text-align: center!important;
}

.myApproval .myApproval-table tbody tr td:nth-child(3),
.myApproval .myApproval-table tbody tr td:nth-child(2) {
    width: 13%;
}
.myApproval .myApproval-table tbody tr td:nth-child(6) {
    width: 8%;
}

.myApproval .container {
	height: auto;
}

</style>
<div class="container">
    <div class="row ">
        <!-- biaoge访问审批界面 -->
            <div class="clearfix myApproval-table-wrap" style=" border: 1px solid #eeeeee; overflow: hidden;">
                <table class="myApproval-table" style="border: none!important;">
                	<?php
                		if (!empty($data)&&count($data)>0){
                	?>
                    <thead style="" class="thead-normal">
                    <tr>
                        <th class="text-center">序号</th>
                        <!--<th class="text-center">资产包编号</th>-->
                        <th class="text-center">名称 </th>
                        <!--<th class="text-center">本金 </th>-->
                        <th class="text-center">省份地区</th>
                        <th class="text-center">申请人</th>
                        <th class="text-center">申请访问理由</th>
                        <th class="text-center">申请时间</th>
                        <th class="text-center">审批结果</th>
                        <th class="text-center">审批意见</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <thead style="" class="thead-fixed">
                    <tr style="border: 1px solid #E2E2E2;">
                        <th class="text-center">序号</th>
                        <!--<th class="text-center">资产包编号</th>-->
                        <th class="text-center">名称 </th>
                        <!--<th class="text-center">本金 </th>-->
                        <th class="text-center">省份地区</th>
                        <th class="text-center">申请人</th>
                        <th class="text-center">申请访问理由</th>
                        <th class="text-center">申请时间</th>
                        <th class="text-center">审批结果</th>
                        <th class="text-center">审批意见</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <?php }?>
                    <tbody>
                    <?PHP
                    $i = 0;
                    $audit_result=Yii::$app->params['audit_result'];
                    if (!empty($data)&&count($data)>0){
                    foreach ($data as $value) {//'result','package.provinceName','package.cityName','user'
                        $str='审批完成';
                        if($value['result']==1){
                            $str='<span class="txt-cut approval" style="cursor:pointer" application_id="'.$value['application_id'].'" result_id="'.$value['result_id'].'" is_package="'.$value['is_package'].'">审批</span>';
                        }
                        $code = !empty($value['code'])?$value['code']:'无编号';
                        $principal = !empty($value['principal'])?$value['principal']:'无本金';

                        $realname = !empty($value['realname'])?$value['realname']:'无申请人';
                        $reason = !empty($value['reason'])?$value['reason']:'无申请访问理由';
                        $applied_at = !empty($value['applied_at'])?$value['applied_at']:'无申请时间	';
                        $auditResult = !empty($audit_result[$value['result']])?$audit_result[$value['result']]:'无审批结果';
                        $note = !empty($value['note'])?$value['note']:'无审批意见	';
                        $i++;
//  资产包编号                    <td title="$code">
//                                   	<span class='txt-cut'>$code</span>
//                       </td>
//       本金          <td title="$principal">
//                                   	<span class='txt-cut'>$principal</span>
//                      </
                        if (!empty($value['is_package'])&&$value['is_package']==2){
                            $packageModel = (new \yii\db\Query())->from('project')->where(['=','id',$value['project_id']])->one();
                            $packageId = $packageModel['package_id'];
                            $title = !empty($value['borrower'])?$value['borrower']:'无标题';
                            $province = !empty($value['province'])?$value['province']:'';
                            $provinceModel = (new \yii\db\Query())->from(\common\models\Country::tableName())->where(['=','id',$province])->one();
                            $city = !empty($value['city'])?$value['city']:'';
                            $cityModel = (new \yii\db\Query())->from(\common\models\Country::tableName())->where(['=','id',$city])->one();
                            $url = "/project/getinfodata?package_id=".$packageId."&project_id=".$value['project_id'];
                        }else{
                            $province = !empty($value['package_province'])?$value['package_province']:'';
                            $provinceModel = (new \yii\db\Query())->from(\common\models\Country::tableName())->where(['=','id',$province])->one();
                            $city = !empty($value['package_city'])?$value['package_city']:'';
                            $cityModel = (new \yii\db\Query())->from(\common\models\Country::tableName())->where(['=','id',$city])->one();
                            $title = !empty($value['package_title'])?$value['package_title']:'无标题';
                            $url = "/package/detail-info?packageid=".$value['package_id'];
                        }
                        $provinceName = !empty($provinceModel['title'])?$provinceModel['title']:'--';
                        $cityName = !empty($cityModel['title'])?$cityModel['title']:'--';
                        echo <<<ACCESS
                                <tr class="text-left" >
                                     <td class="clearfix text-center" >
                                     	<span class='txt-cut'>$i</span>
                                     </td>
                                     <td title="$title">
                                     	<a href="$url" target="_blank">
                                     		<span class='txt-cut'style="color:#2096f1;cursor:pointer;">$title</span>
                                     	</a>
                                     </td>
                                     <td >
                                     	<span class='txt-cut' title="$provinceName.$cityName">$provinceName.$cityName</span>
                                     </td>
                                     <td title="$realname">
                                     	<span class='txt-cut'>$realname</span>
                                     </td>
                                     <td title="$reason"><span class="txt-cut">$reason</span>
                                     	
                                     </td>
                                     <td title="$applied_at">
                                     	<span class='txt-cut'>$applied_at</span>
                                     </td>
                                     <td title="$auditResult">
                                     	<span class='txt-cut'>$auditResult</span>
                                     </td>
                                     <td title="$note"><span class="txt-cut">$note</span></td>
                                     <td>
                                     	<span >$str</span>
                                     </td>
                                </tr>
ACCESS;

//                        $package = $value['package'];
//                        $provinceName=$package['provinceName'];
//                        $cityName=$package['cityName'];
//                        $result = $value['result'];
//                        $user = $value['user'];
//                        $str='审批完成';
//                        if($result['result']==1){
//                            $str='<span class="txt-cut approval"  application_id="'.$result['application_id'].'" result_id="'.$result['id'].'" >审批</span>';
//                        }
//                        echo ' <tr class="text-left" >
//                                            <td class="clearfix text-center" >'.$i.'</td>
//                                            <td title="">'.$package['code'].'</td>
//                                            <td title="'.$package['title'].'">'.$package['title'].'</td>
//                                            <td title="'.$package['principal'].'">'.$package['principal'].'</td>
//                                            <td title="">'.$provinceName['title'].$cityName['title'].'</td>
//                                            <td title="'.$user['realname'].'">'.$user['realname'].'</td>
//                                            <td title="'.$value['reason'].'"><span class="txt-cut">'.$value['reason'].'</span></td>
//                                            <td title="">'.$value['applied_at'].'</td>
//                                            <td title="">'.$audit_result[$result['result']].'</td>
//                                            <td title="'.$result['note'].'"><span class="txt-cut">'.$result['note'].'</span></td>
//                                            <td title="审批">'.$str.'</td>
//                                        </tr>';
                    }
                    }else{
                        echo <<<NULLPAGE
<div class="defaultPage">
        <div class="defaultPage-nothing">
            <img src="/image/defaultPage/nothing.png" style='width: 100%;'>
        </div>
    </div>
NULLPAGE;
                    }
                    ?>
                    </tbody>
                </table>
            </div>
            <div class="pagingBox">
                <?PHP
                echo LinkPager::widget([
                    'pagination' => $pages,
                    'firstPageLabel' => '首页',
                    'lastPageLabel' => '尾页',
                    'nextPageLabel' => '下一页',
                    'prevPageLabel' => '上一页',
                ]);
                ?>
            </div>
    </div>
</div>
<script>
    /*立项审批 点击审批弹出模态框及填写显示信息*/
    $(".approval").click(function(){
        var objTr=$(this).parents("tr");
        $("#packageName").html(objTr.find("td").eq(1).attr("title"));
        $("#proposerUser").html(objTr.find("td").eq(3).attr("title"));
        $("#noteDetail").html(objTr.find("td").eq(4).attr("title"));
        $("#note").html(objTr.find("td").eq(8).attr("title"));
        $("#application_id").val($(this).attr("application_id"));
        $("#result_id").val($(this).attr("result_id"));
        $("#is_package").val($(this).attr("is_package"));
        $("#AssetPackageEditing-approval").modal();
    });
</script>